from page.net_project_page import NetProjectPage
from page.common_tools import CommonTools
from common.page import IOS, XPATH
import random as r
import time as t


today = t.strftime('%Y%m%d', t.localtime(t.time()))


class zizhuArticlePage(NetProjectPage, CommonTools):

    def release_article(self, title='%s自动化测试文章%d' % (today, r.randint(100, 999)), flag=0):
        # flag为学生标识，如果是学生需要输入推荐理由
        self.find_button("common release").click()
        t.sleep(2)
        if flag:
            self.find_static_text("推荐理由").click()
            self.find_element(
                XPATH, '//XCUIElementTypeOther/XCUIElementTypeTextView'  # 推荐理由输入框
            ).send_keys('这是推荐理由，学生角色需输入此内容，否则不能发布')
            self.find_button("确定").click()
        self.find_static_text(string="请输入标题", attr='value', contains_flag=1).click()
        self.find_static_text(string="请输入标题", attr='value', contains_flag=1).send_keys(title)
        self.hide_keyboard()
        self.swipe(10, 140, 10, 140)  # 点击文章内容
        t.sleep(2)
        self.Edit_all()
        self.Fujian()
        self.find_button("下一步").click()
        self.ZIJian()
        self.find_button("发布").click()
        t.sleep(2)
        self.Select_btn()
        self.ZIJian()
        self.find_button("更新草稿").click()
        t.sleep(1)
        self.find_static_text("删除").click()
        self.find_button("确定").click()
        self.find_static_text("参考资料").click()
        self.find_button("common back dark icon").click()
        self.find_button("common back light icon").click()




    def view_comment_article(self, title='自动化测试文章'):
        # self.CaoG()
        self.Select_Biao()
        self.find_button("common back dark icon").click()
        self.find_static_text("我的草稿").click()
        t.sleep(2)
        self.find_static_text("我的相关回复").click()
        # self.find_static_text(string=title, contains_flag=1).click()
        # t.sleep(2)
        # self.swipe(20,696,20,696)  #点击评论
        # self.find_element(*self.comment_text).send_keys('这是二级评论的内容。。。。相反，那种不知敬畏的人是从不在人格上反省自己，而且内心没有丝毫不安。这样的人尽管有再多的艳遇，也不知什么是光荣。不相信神圣 的人，必被世上一切神圣的事物所抛弃。')
        # self.find_button("发布").click()
        # t.sleep(2)
        self.find_button(string="common back dark icon", contains_flag=1).click()
        t.sleep(0.5)
        self.find_button(string="common back light icon", contains_flag=1).click()


if __name__ == '__main__':
    test = zizhuArticlePage()
    test.enter_project()
    test.enter_tools('文章')
    test.release_article()
    test.view_comment_article()
